package future优化.回调版的future;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @author ZhuQi
 * @ClassName MyFutureTask
 * @Date 2022/9/5 14:32
 * @Version 1.0
 * @Description TODO
 */
public class MyFutureTask<U> extends FutureTask<U> {

    /**
     * Creates a {@code FutureTask} that will, upon running, execute the
     * given {@code Callable}.
     *
     * @param callable the callable task
     * @throws NullPointerException if the callable is null
     */
    public MyFutureTask(Callable<U> callable) {
        super(callable);
    }

    /**
     * Creates a {@code FutureTask} that will, upon running, execute the
     * given {@code Runnable}, and arrange that {@code get} will return the
     * given result on successful completion.
     *
     * @param runnable the runnable task
     * @param result   the result to return on successful completion. If
     *                 you don't need a particular result, consider using
     *                 constructions of the form:
     *                 {@code Future<?> f = new FutureTask<Void>(runnable, null)}
     * @throws NullPointerException if the runnable is null
     */
    public MyFutureTask(Runnable runnable, U result) {
        super(runnable, result);
    }

    @Override
    public void run() {
        long id = Thread.currentThread().getId();
        FutureMap.setFutureMap(id, this);

        super.run();
    }
}
